﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Objects.DataClasses;
using System.Linq;
using AppLab.Data.Models;
using AppLab.Web.Resources;
using Wicresoft.AppFlow.Flows;

namespace AppLab.Web
{
    public sealed partial class Brand
    {
        [Key]
        public int BrandId { get; set; }

        public string BrandName { get; set; }

        public string BrandNameEN { get; set; }

        public string BrandNameEN1 { get; set; }

        public string BrandNameEN2 { get; set; }

        public void AddMbBrand()
        {
            using (var dc = PMSEntities.Create())
            {
                var e = new MobileBrand();
                e.BrandName = BrandName;
                dc.MobileBrands.AddObject(e);
                dc.SaveChanges();
            }
        }

        /// <summary>
        /// 比较该品牌是否存在，返回TRUE，表示已经存在该品牌
        /// </summary>
        /// <param name="BrandName"></param>
        /// <returns></returns>
        public bool Exist()
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.MobileBrands.FirstOrDefault(p => p.BrandName == this.BrandName) != null;
            }
        }
    }
}